<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<!--{hook admin_group_list_start.htm}-->
<div class="container-fluid">
<div class="row">
	<div class="col-12">
		<div class="card">
			<div class="card-body">
				<form action="<?php echo url('group-list', '', TRUE);?>" method="post" id="form">
					<input type="hidden" name="safe_token" value="<?php echo $safe_token;?>" />
					<div class="table-responsive arrlist">
						<table class="table" style="min-width: 600px">
							<thead>
								<tr>
									<th class="text-center"><?php echo lang('group_id');?></th>
									<th class="text-center"><?php echo lang('group_name');?></th>
									<th class="text-center"><?php echo lang('group_credits_from');?></th>
									<th class="text-center"><?php echo lang('group_credits_to');?></th>
									<th class="text-center"><?php echo lang('edit');?></th>
									<th class="text-center"><?php echo lang('delete');?></th>
								</tr>
							<thead>
							<tbody>
								<?php foreach($grouplist as $_gid=>$_group) { ?>
								<tr align="center" rowid="<?php echo $_gid; ?>">
									<td><input type="text" class="form-control" name="_gid[<?php echo $_gid;?>]" value="<?php echo $_group['gid']; ?>"  placeholder="<?php echo lang('group_id');?>" style="width:60px;" /></td>
									<td><input type="text" class="form-control" name="name[<?php echo $_gid;?>]" value="<?php echo $_group['name']; ?>" placeholder="<?php echo lang('group_name');?>" style="width:100px;" /></td>
									<td><input type="text" class="form-control" name="creditsfrom[<?php echo $_gid;?>]" value="<?php echo $_group['creditsfrom']; ?>" placeholder="<?php echo lang('group_credits_from');?>" style="width:100px;" /></td>
									<td><input type="text" class="form-control" name="creditsto[<?php echo $_gid;?>]" value="<?php echo $_group['creditsto']; ?>" placeholder="<?php echo lang('group_credits_to');?>" style="width:100px;" /></td>
									<td><a class="btn row_edit" role="btn"><?php echo lang('edit');?></a></td>
									<td><?php if(!in_array($_gid, $system_group)) { ?><a class="btn row_delete" role="btn"><?php echo lang('delete');?></a><?php } ?></td>
								</tr>
								<?php } ?>
							</tbody>
						</table>
					</div>
					<p><a role="button" class="btn row_add">[+]<?php echo lang('add_new_line');?></a></p>
					<p class="text-center">
						<button type="submit" class="btn btn-danger " id="submit" data-loading-text="<?php echo lang('submiting');?>..." style="width: 10rem;"><?php echo lang('confirm');?></button>
					</p>
				</form>
				<p class="small text-grey"><?php echo lang('tips');?>：<?php echo lang('forum_edit_tip');?></p>
			</div>
		</div>
	</div>
</div>
</div>
<!--{hook admin_group_list_end.htm}-->

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>

<script>
var maxgid = <?php echo $maxgid;?>;
var jform = $("#form");
jform.on('submit', function(){
	jform.reset();
    var jthis = $(this);
    var jsubmit = jthis.find('#submit');
	jsubmit.button('loading');
	var postdata = jform.serialize();
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			$.alert(message);
			jsubmit.text(message).delay(1000).location();
		} else {
			alert(message);
			jsubmit.button('reset');
		}
	});
	return false;
});

/*编辑*/
var jarrlist = $('.arrlist');
var jedit = $('a.row_edit');
jarrlist.on('click', 'a.row_edit', function() {
	var jthis = $(this);
	var jtr = jthis.parents('tr');
	var rowid = jtr.attr('rowid');
	window.location = xn.url('group-update', {gid:rowid}, true);
});

/*删除*/
var jdelete = $('a.row_delete');
jarrlist.on('click', 'a.row_delete', function() {
	var jthis = $(this);
	var jtr = jthis.parents('tr');
	var rowid = jtr.attr('rowid');
	jtr.remove();
	return false;
});
/*增加*/
var jadd = $('a.row_add');
jadd.on('click', function() {
	var jclone = jarrlist.find('tr').last().clone();
	jclone.insertAfter(jarrlist.find('tr').last());
	var jgid = jclone.find('input[name^="_gid"]');
	var rowid = ++maxgid;
	jgid.val(rowid);
	jclone.attr('rowid', rowid);
	
	/*清空值*/
	jclone.find('input').not('[name^="_gid"]').val('');
	
	/*修改 [] 中的值为 rowid*/
	jclone.find('input').attr_name_index(rowid);
	
	return false;
});

$('#user').addClass('show');
$('li.user, .menu-group').addClass('active').find('a').removeClass('collapsed');
</script>

<!--{hook admin_group_list_js.htm}-->